package com.xjtu.platform.common.dao;

import com.xjtu.platform.common.Cache;
import com.xjtu.platform.common.model.User.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface CommonDao {

    @Select("select user_id userId,user_name userName,avatar_path avatar,user_pwd userPwd,favor favor  from user where user_id = #{userId}")
    User findUserById(String userId);

    @Select("select * from cache where cache_id = #{cache_id}")
    Cache findCacheByKey(String cache_id);

    @Select("select * from cache where cache_id = #{cache_id} and time> #{currentTime} - #{limit}")
    Cache findCacheByKeyNearTime(String cache_id,Long currentTime, Long limit);

    @Insert("insert into cache (cache_id, value, time) values(#{cache_id}, #{value}, #{time})")
    void setCache(Cache cache);

    @Insert("update cache set value = #{value}, time = #{time} where cache_id = #{cache_id}")
    void updateCache(Cache cache);

    @Delete("delete from cache where cache_id = #{cache_id}")
    void deleteCache(String cache_id);
}